const isEmpty = (str) => {
  if (str == null || str == "" || str == undefined) {
    return true;
  }
  return false;
}

const getAreaInfo = (data) => {
  if (isEmpty(data)) {
    return "-";
  }
  return data.replace(",", " ");
}

const size2Str = (limit) => {
  var size = "";
  if (limit < 0.1 * 1024) {
    size = limit.toFixed(2) + "B"
  } else if (limit < 1024 * 1024) {
    size = (limit / 1024).toFixed(2) + "KB"
  } else if (limit < 1024 * 1024 * 1024) {
    size = (limit / (1024 * 1024)).toFixed(2) + "MB"
  } else {
    size = (limit / (1024 * 1024 * 1024)).toFixed(2) + "GB"
  }
  var sizeStr = size + "";
  var index = sizeStr.indexOf(".");
  var dou = sizeStr.substring(index + 1, 2)
  if (dou == "00") {
    return sizeStr.substring(0, index) + sizeStr.substr(index + 3, 2)
  }
  return size;
}

const copyText = (content)=> {
  if (!content) {
      return
  }
  let cInput = document.createElement("input")
  document.body.appendChild(cInput)
  cInput.value = content
  cInput.select()
  document.execCommand("copy")
  document.body.removeChild(cInput)
}

export default {
  isEmpty,
  getAreaInfo,
  size2Str,
  copyText
}
